package part_03_The_Synchronized_Keyword;

public class App0 {

	int count = 0;

	synchronized void incrementCount() {

		count++;

	}

	public static void main(String[] args) {
		App0 a1 = new App0();
		a1.doWork();
	}

	private void doWork() {

		Thread t1 = new Thread(new Runnable() {

			@Override
			public void run() {
				for (int i = 0; i < 10000; i++) {

					incrementCount();
				}

			}
		});

		Thread t2 = new Thread(new Runnable() {

			@Override
			public void run() {
				for (int i = 0; i < 10000; i++) {

					incrementCount();
				}

			}
		});

		t1.start();
		t2.start();

		try {
			t1.join();
			t2.join();

		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("count  :" + count);
	}

}
